package com.haibara.codesandbox.core;

import com.github.dockerjava.api.command.CreateContainerResponse;
import com.haibara.codesandbox.model.ExecuteCodeRequest;
import com.haibara.codesandbox.model.QuestionCase;
import com.haibara.codesandbox.model.RunCodeResult;

import java.util.concurrent.ExecutionException;

/**
 * @Author: mengyu
 * @Date: 2025/5/3
 */
public abstract class CodeSandboxTemplate {

    public abstract void saveCodeToFile(String code, Long questionId, Long userId);

    public abstract String[] getCmdStrings(QuestionCase questionCase, Long questionId, Long userId);

    public abstract RunCodeResult runCode(
            CreateContainerResponse container, QuestionCase questionCase, Long userId,
            Long questionId, Long questionSubmitId, Integer timeLimit
    ) throws Exception;

    /**
     * 串联saveCodeToFile、getCmdStrings、runCode
     * @param executeCodeRequest 执行代码请求
     * @throws Exception 异常
     */
    public abstract void executeCode(ExecuteCodeRequest executeCodeRequest) throws Exception;
}
